package com.newtouch.bxzs.enterprise.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.newtouch.bxzs.common.base.model.PersonalCustomerGroup;
import com.newtouch.bxzs.enterprise.model.bo.PersonalCustomerGroupBO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 个人客户分组Mapper层
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020/12/25 9:45</td>
 * <td>yuanjie</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Mapper
public interface PersonalCustomerGroupMapper extends BaseMapper<PersonalCustomerGroup> {

    @Select("SELECT\n" +
            "\tcount(m.CUSTOMER_ID) as count,\n" +
            "\tg.GROUP_NAME,\n" +
            "\tg.GROUP_ID \n" +
            "FROM\n" +
            "\tASSISTANT_CUSTOMER_GROUP g\n" +
            "\tLEFT JOIN ASSISTANT_CUSTOMER_GROUP_MAP m ON g.GROUP_ID = m.GROUP_ID\n" +
            "WHERE\n" +
            "\tg.CREATE_USER_ID = #{createUserId} \n" +
            "\tAND g.IS_DELETE = 0 \n" +
            "GROUP BY\n" +
            "\tg.GROUP_ID;")
    List<PersonalCustomerGroupBO> getGroupList(@Param("createUserId") String createUserId);
}
